#!/bin/bash
# prescript.sh - Qt编译前执行的脚本

## 创建运行保护

echo "shell start"

p_own=$(cd $(dirname $0); pwd)
cd $p_own

if [ -f "shell_protect.txt" ]; then
    echo "bat is run protected"
    exit 
fi

echo "shell is protected " > shell_protect.txt
## --------------------------------------------------------------------
## 增加输出日志: 工程层
cd ../

echo "---                         " >> readme.md
echo "### $(date +"%Y-%m-%d %H:%M:%S")" >> readme.md
echo "*                           " >> readme.md
echo "*                           " >> readme.md
code readme.md &

## --------------------------------------------------------------------
## 同步特定文件到window：双工程层
srcUbuntu=$(basename "$PWD")
dstWindow="${srcUbuntu//ubuntu/window}"  # 双斜杠表示全局替换

cd ../
cp -rf $srcUbuntu/src             $dstWindow
cp -rf $srcUbuntu/public_resource $dstWindow
cp -rf $srcUbuntu/qt_bat          $dstWindow

cp -f "$srcUbuntu/main.cpp"       "$dstWindow/main.cpp"       
cp -f "$srcUbuntu/mainwindow.cpp" "$dstWindow/mainwindow.cpp" 
cp -f "$srcUbuntu/mainwindow.h"   "$dstWindow/mainwindow.h"   
cp -f "$srcUbuntu/mainwindow.ui"  "$dstWindow/mainwindow.ui"  
cp -f "$srcUbuntu/ui_mainwindow.ui"  "$dstWindow/ui_mainwindow.ui"  
cp -f  $srcUbuntu/*.pro $dstWindow

## --------------------------------------------------------------------
## 返回目录并延时释放
cd $p_own
sleep 4  
rm -rf shell_protect.txt
